//
//  ViewController.m
//  ExcelListDemo
//
//  Created by Cluy on 15/6/15.
//  Copyright (c) 2015年 RUNLIN. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    _tableview.delegate = self;
    _tableview.dataSource = self;
    _tableViewList = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"2",@"1",@"2",@"1",@"2"];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)initlistView:(UIButton *)btn andSourceList:(NSArray *)list{
    tableVC =[[YDTableView alloc] initWithStyle:UITableViewStylePlain];
    tableVC.view.frame = CGRectMake(btn.frame.origin.x,btn.frame.origin.y+btn.frame.size.height, btn.frame.size.width, 150);
    tableVC.sourcelist = list;
    tableVC.delegate = self;
    [self.view addSubview:tableVC.view];
}
- (IBAction)selectTypeBtn1:(id)sender {
    UIButton *btn = sender;
    NSArray *arr =@[@"",@"1",@"2",@"3"];
    [self initlistView:btn andSourceList:arr];
    
}


//delegate
-(void)getValue:(NSString*)selectValue{

    _tableViewList = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"2",@"1",@"2",@"1",@"2"];
    if ([selectValue isEqualToString:@""]){
        [self.tableview reloadData];
        tableVC.view.hidden = YES;
        return;
    }
    NSLog(@"SELECTVALUE = %@",selectValue);
    //todo :筛选后值重新load
    NSMutableArray *tempArr = [NSMutableArray array];
    [_tableViewList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        if ([[_tableViewList objectAtIndex:idx]isEqualToString:selectValue]) {
            [tempArr addObject:[_tableViewList objectAtIndex:idx]];
        }
    }];
    _tableViewList = tempArr;
    [self.tableview reloadData];
    tableVC.view.hidden = YES;
   
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

#pragma mark -
#pragma mark Table view datasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [_tableViewList count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    
    
    NSUInteger row = [indexPath row];
    cell.textLabel.text = [_tableViewList objectAtIndex:row];
    
    return cell;
}

#pragma mark -
#pragma mark Table view delegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 40;
}

@end
